package com.ruoyi.web.controller.system;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Point;
import com.ruoyi.system.service.IntepralSettingService;
import com.ruoyi.system.service.PointService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author HP
 * @Date 2021/3/10
 * @Description TODO
 */
@RestController
@RequestMapping("/integral/point")
public class PointController {
    @Autowired
    private PointService pointService;
    @Autowired
    private IntepralSettingService intepralSettingService;

    @RequestMapping("queryByUserId")
    public AjaxResult queryByUserId(String user_id){
        Point point = pointService.queryByUserId(user_id);
        return AjaxResult.success(point);
    }

    @RequestMapping("addUserForPoint")
    public AjaxResult addUserForPoint(String userId, Integer isStu){
        try {
            Point point=new Point();
            point.setIs_stu(isStu);
            point.setUser_id(userId);
            point.setPoint(0);
            point.setAccumulated_integral(0);
            point.setIs_delete(0);
            pointService.savePoint(point); //插入积分信息
            intepralSettingService.addIntepral(userId,2); //注册加分项
            return AjaxResult.success(point);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.error(e.getMessage());
        }
    }
}
